int shmid = ::shmget(k, gShmSize, IPC_CREAT | IPC_EXCL);
if (shmid < 0)
{
    // 创建失败
    cerr << "shmget error" << endl;
    return 2;
}
cout << "shmid: " << shmid << endl;

void *GetAddr()
{
    return _addr;
}

// 获取共享内存的属性
void ShmMeta()
{
    struct shmid_ds buffer; // 系统提供的数据类型
    // 获取属性 输出到buffer中
    int n = ::shmctl(_shmid, IPC_STAT, &buffer);
    if (n < 0)
        return;

    cout << "########################" << endl;
    cout << buffer.shm_atime << endl;             // 最后attach时间
    cout << buffer.shm_cpid << endl;              // 创建该共享内存段的进程ID
    cout << buffer.shm_ctime << endl;             // 创建时间
    cout << buffer.shm_nattch << endl;            // 该共享内存的挂接进程数
    cout << ToHex(buffer.shm_perm.__key) << endl; // 其键值转换为16进制
    cout << "########################" << endl;
}

// 创建共享内存
void CreateShm()
{
    if (_shmid == -1)
    {
        // 传入对应权限即可
        CreateShmHelper(IPC_CREAT | IPC_EXCL | gMode);
    }
    cout << "key: " << ToHex(_key) << endl;
}

struct task_struct
{
    //...
    /* signal handlers */
    struct sighand_struct *sighand;
    sigset_t blocked;
    struct sigpending pending;
    // ...
};

struct sighand_struct
{
    atomic_t count;
    struct k_sigaction action[_NSIG]; // #define _NSIG 64
    spinlock_t siglock;
};

struct k_sigaction
{
    struct __new_sigaction sa;
    void __user *ka_restorer;
};

struct __new_sigaction
{
    __sighandler_t sa_handler;
    unsigned long sa_flags;
    void (*sa_restorer)(void); /* Not used by Linux/SPARC */
    __new_sigset_t sa_mask;
};

/* Type of a signal handler. */
typedef void (*__sighandler_t)(int);
struct sigpending
{
    struct list_head list;
    sigset_t signal;
};

void PrintPending()
{
    sigset_t pending;
    sigpending(&pending);

    cout << "pending: ";
    for (int signo = 31; signo > 0; --signo)
    {
        //判断是否在其中
        if (sigismember(&pending, signo))
        {
            cout << 1;
        }
        else 
        {
            cout << 0;
        }
    }
    cout << endl;
}


void handler(int signo)
{
    static int cnt = 0;
    ++cnt;
    while (true)
    {
        std::cout << "get a sig: " << signo << ", cnt:" << cnt << std::endl;
        PrintPending();
        sleep(1);
        //break;
    }
    //exit(1);
}

int main()
{
    struct sigaction act, oact;
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    //添加屏蔽信号
    sigaddset(&act.sa_mask, 3);
    sigaddset(&act.sa_mask, 4);
    sigaddset(&act.sa_mask, 5);
    sigaddset(&act.sa_mask, 6);

    ::sigaction(2, &act, &oact);

    while (true)
    {
        //PrintBlock();
        PrintPending();
        pause();
    }
    return 0;
}

